package org.wzl.todolisthelper.convert;

import org.mapstruct.BeforeMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.wzl.todolisthelper.domain.TaskEvent;
import org.wzl.todolisthelper.enumerate.AddTaskEventDTO;
import org.wzl.todolisthelper.utils.IdCommonGen;
import org.wzl.todolisthelper.utils.UserUtil;

@Mapper(componentModel = "spring")
public interface TaskEventConvert {

    @Mapping(target = "eventType", ignore = true)
    TaskEvent toDO(AddTaskEventDTO addTaskEventDTO);
    @BeforeMapping
    default void toDOBeforeMapping(@MappingTarget TaskEvent taskEvent, AddTaskEventDTO addTaskEventDTO) {
        taskEvent.setId(IdCommonGen.generateId());
        taskEvent.setEventType(addTaskEventDTO.getEventType().getCode());
        taskEvent.setUserId(UserUtil.getCurrentUserId());
    }

}
